package com.bps.zzant.json;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.bps.zzant.model.Customer;
import com.bps.zzant.model.Product;
import com.bps.zzant.services.ProductService;

@Controller
public class ProductJSON {
	private static final Logger logger = LoggerFactory.getLogger(ProductJSON.class);
	
	@Autowired
	private ProductService productService;
	
	@RequestMapping(value = "getProductByStyleNo.json", method = RequestMethod.GET)
	public Map getProductByStyleNo(HttpServletRequest request, HttpServletResponse response){
		
		Enumeration<String> a = request.getParameterNames();
	    for (; a.hasMoreElements(); ) {
	        logger.info("????????????"+(String)a.nextElement());
	    }
	        
	        
		logger.info(" +++++++++in ProductJSON.getProductByStyleNo styleNo:"+ request.getParameter("styleNo"));

		String styleNo = request.getParameter("styleNo");
		if(styleNo==null){
			styleNo="";
		}else {
			styleNo=styleNo+"%";
		}
		
		Map<String, Object> map = new HashMap<String, Object>();
		
		List<Product> productList = productService.getProductByStyleNo(styleNo);
		logger.info(" +++++++++in ProductJSON.getProductByStyleNo productList size:"+productList.size());
		

		map.put("productList", productList);
		return map;
		
		
	}
	
}
